//
//  XLUserDefaults.m
//  campus
//
//  Created by xl on 2019/11/27.
//  Copyright © 2019 xl. All rights reserved.
//

#import "XLUserDefaults.h"

NSString *const kUserDefaultKeyCurrUserJson = @"kUserDefaultKeyCurrUserJson";

NSString *const KServerTimeLocalDiffTime = @"KServerTimeLocalDiffTime";//服务器时间戳和本地时间戳的差

NSString *const KLastLoginPhone = @"KLastLoginPhone";//记录上次登录的手机号

NSString *const kUserAvailableToken = @"kUserAvailableToken";//用户有效登录token

NSString *const kUserLoginPassword = @"kUserLoginPassword";//用户登录密码

NSString *const kUserLoginWay = @"kUserLoginWay";//用户登录方式

NSString *const kUserNumPassword = @"kUserNumPassword";//用户储层的数字密码（从后台回到前台使用）

NSString *const kUserGesturePassword = @"kUserGesturePassword";//用户储存手势密码（从后台回到前台使用）

@interface XLUserDefaults ()

@end

@implementation XLUserDefaults

/** 保存上次手机登录的账号 **/
+ (void)saveLastLoginPhone:(NSString *)phone
{
    if (ISEmptyString(phone)) {
        return;
    }
    [XLStandardUserDefaults setObject:phone forKey:KLastLoginPhone];
    [XLStandardUserDefaults synchronize];
}

+ (NSString *)getLastLoginPhone
{
    NSString *phone = [XLStandardUserDefaults objectForKey:KLastLoginPhone];
    return phone;
}

+ (void)updateServerDiffTime:(NSTimeInterval)diffTime
{
    [XLStandardUserDefaults setDouble:diffTime forKey:KServerTimeLocalDiffTime];
    [XLStandardUserDefaults synchronize];
}

+ (NSTimeInterval)getServeDiffTime
{
    NSTimeInterval diff = [XLStandardUserDefaults doubleForKey:KServerTimeLocalDiffTime];
    return diff;
}

//存储上次登录用户信息
+ (void)saveCurrentLoginUserJson:(NSData *)data {
    if (nil == data) {
        [XLStandardUserDefaults removeObjectForKey:kUserDefaultKeyCurrUserJson];
    }
    else{
        [XLStandardUserDefaults setObject:data forKey:kUserDefaultKeyCurrUserJson];
        
    }
    [XLStandardUserDefaults synchronize];
}

+ (NSData *)getCurrentLoginUserInfoJson {
    NSData *userInfo = [XLStandardUserDefaults objectForKey:kUserDefaultKeyCurrUserJson];
    return userInfo;
}

/** 保存上次有效token **/
+ (void)saveLastAvailableToken:(NSString *)token {
    if (ISEmptyString(token)) {
        [XLStandardUserDefaults removeObjectForKey:kUserAvailableToken];
    } else {
        [XLStandardUserDefaults setObject:token forKey:kUserAvailableToken];
    }
    [XLStandardUserDefaults synchronize];
}

+ (NSString *)getLastAvailableToken {
    NSString *token = [XLStandardUserDefaults objectForKey:kUserAvailableToken];
    return token;
}

+ (void)saveLastLoginPassword:(NSString *)password {
    if (ISEmptyString(password)) {
        [XLStandardUserDefaults removeObjectForKey:kUserLoginPassword];
    } else {
        [XLStandardUserDefaults setObject:password forKey:kUserLoginPassword];
    }
    [XLStandardUserDefaults synchronize];
}

+ (NSString *)getLastLoginPassword {
    return [XLStandardUserDefaults objectForKey:kUserLoginPassword];;
}


+ (void)saveLastLoginWay:(XLLoginWayType)type {
    [XLStandardUserDefaults setInteger:type forKey:kUserLoginWay];
    [XLStandardUserDefaults synchronize];
}

+ (NSInteger)getLastLoginWay {
    return [XLStandardUserDefaults integerForKey:kUserLoginWay];
}

/** 存储数字密码 */
+ (void)saveLastNumPassword:(NSString *)password {
    if (ISEmptyString(password)) {
        [XLStandardUserDefaults removeObjectForKey:kUserNumPassword];
    } else {
        [XLStandardUserDefaults setObject:password forKey:kUserNumPassword];
    }
    [XLStandardUserDefaults synchronize];
}

+ (NSString *)getLastNumPassword {
    return [XLStandardUserDefaults objectForKey:kUserNumPassword];;
}

/** 存储手势密码 */
+ (void)saveLastGesturePassword:(NSString *)password {
    if (ISEmptyString(password)) {
        [XLStandardUserDefaults removeObjectForKey:kUserGesturePassword];
    } else {
        [XLStandardUserDefaults setObject:password forKey:kUserGesturePassword];
    }
    [XLStandardUserDefaults synchronize];
}

+ (NSString *)getLastGesturePassword {
    return [XLStandardUserDefaults objectForKey:kUserGesturePassword];;
}

/** 头像路径存储 */
+ (void)saveAvaterPath:(NSString *)path {
    if (ISEmptyString(path)) {
        [XLStandardUserDefaults removeObjectForKey:@"kAvaterPath"];
    } else {
        [XLStandardUserDefaults setObject:path forKey:@"kAvaterPath"];
    }
    [XLStandardUserDefaults synchronize];
}

+ (NSString *)getAvaterPath {
    return [XLStandardUserDefaults objectForKey:@"kAvaterPath"];;
}

@end
